package generadorDescriptores.database;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.project.frba.bi.extraction.ExtractionResult;

public class DatabaseResult implements ExtractionResult {
	
	private ResultSet resultSet;
	
	public DatabaseResult(ResultSet resultSet){
		this.resultSet = resultSet;
		this.next();
	}

	public boolean hasNext() {
		Boolean hasNext = false;
		try {
			
			hasNext = this.resultSet.next();
			this.resultSet.previous();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return hasNext;
	}

	public void next() {
		try {
			this.resultSet.next();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public <T> T getValue(String key, Class<T> returnType){
		Object keyObject = null;
		try {
			keyObject =  this.resultSet.getObject(key);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		if(keyObject != null){ 
			return returnType.cast(keyObject);
		}
		return null;
	}

	public Long getMetric() {
		try {
			return this.resultSet.getLong("metric");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
